﻿using System;

namespace Borg
{
    public sealed class RepositoryId
    {
        private readonly int _hashCode;

        public Uri Uri { get; private set; }

        public string Name { get; private set; }

        public DateTime? LastWriteTime { get; internal set; }

        public RepositoryId(Uri uri, string name, DateTime? lastWriteTime)
            : this(uri, name)
        {
            LastWriteTime = lastWriteTime;
        }

        public RepositoryId(Uri uri, string name)
        {
            Uri = uri;
            Name = name;
            _hashCode = ToString().ToLower().GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (!(obj is RepositoryId))
                return false;

            return ToString().Equals(obj.ToString(), StringComparison.CurrentCultureIgnoreCase);
        }

        public override int GetHashCode()
        {
            return _hashCode;
        }

        public override string ToString()
        {
            return Uri + ";" + Name;
        }
    }
}

